import 'dart:async';

import 'package:flutter/services.dart';

class DeviceIdentifierPlus {
  static const MethodChannel _channel = MethodChannel('device_identifier_plus');
  static bool neverAskAgain = false;

  /// 获取平台版本
  static Future<String?> get platformVersion async {
    final String? version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  static Future<String> get imeiCode async {
    final String imei = await _channel.invokeMethod('getIMEI');
    return imei;
  }

  static Future<List<String>> get imeiMulti async {
    final List<String>? imeis = await _channel.invokeListMethod('getImeiMulti');
    return imeis ?? [];
  }

  static Future<String> get serialCode async {
    final String serial = await _channel.invokeMethod('getSerial');
    return serial;
  }

  static Future<String> get androidID async {
    final String androidID = await _channel.invokeMethod('getAndroidID');
    return androidID;
  }

  static Future<Map> get idMap async {
    final aaa = await _channel.invokeMethod('getIdMap');
    final Map idMap = await _channel.invokeMethod('getIdMap');
    return idMap;
  }

  /// 询问权限
  static Future<bool> requestPermission() async {
    Map permissionMap = await _channel.invokeMethod('requestPermission');
    neverAskAgain = permissionMap["neverAskAgain"];
    final bool result = permissionMap["status"];
    return result;
  }

  static Future<bool> checkPermission() async {
    final bool result = await _channel.invokeMethod('checkPermission');
    print("Checking permission: $result");
    return result;
  }

  static Future<bool> checkPermissionRationale() async {
    final bool result = await _channel.invokeMethod('checkPermissionRationale');
    print("Did the user rejected the permission?: $result");
    return result;
  }

  static void openSettings() async {
    _channel.invokeMethod("openSettings");
  }
}
